package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RptPurchase;
import com.ruoyi.system.service.IRptPurchaseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购原始数据Controller
 * 
 * @author ruoyi
 * @date 2025-06-18
 */
@Controller
@RequestMapping("/system/purchase")
public class RptPurchaseController extends BaseController
{
    private String prefix = "system/purchase";

    @Autowired
    private IRptPurchaseService rptPurchaseService;

    @RequiresPermissions("system:purchase:view")
    @GetMapping()
    public String purchase()
    {
        return prefix + "/purchase";
    }

    /**
     * 查询采购原始数据列表
     */
    @RequiresPermissions("system:purchase:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RptPurchase rptPurchase)
    {
        startPage();
        List<RptPurchase> list = rptPurchaseService.selectRptPurchaseList(rptPurchase);
        return getDataTable(list);
    }

    /**
     * 导出采购原始数据列表
     */
    @RequiresPermissions("system:purchase:export")
    @Log(title = "采购原始数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RptPurchase rptPurchase)
    {
        List<RptPurchase> list = rptPurchaseService.selectRptPurchaseList(rptPurchase);
        ExcelUtil<RptPurchase> util = new ExcelUtil<RptPurchase>(RptPurchase.class);
        return util.exportExcel(list, "采购原始数据数据");
    }

    /**
     * 新增采购原始数据
     */
    @RequiresPermissions("system:purchase:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存采购原始数据
     */
    @RequiresPermissions("system:purchase:add")
    @Log(title = "采购原始数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RptPurchase rptPurchase)
    {
        return toAjax(rptPurchaseService.insertRptPurchase(rptPurchase));
    }

    /**
     * 修改采购原始数据
     */
    @RequiresPermissions("system:purchase:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        RptPurchase rptPurchase = rptPurchaseService.selectRptPurchaseById(id);
        mmap.put("rptPurchase", rptPurchase);
        return prefix + "/edit";
    }

    /**
     * 修改保存采购原始数据
     */
    @RequiresPermissions("system:purchase:edit")
    @Log(title = "采购原始数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RptPurchase rptPurchase)
    {
        return toAjax(rptPurchaseService.updateRptPurchase(rptPurchase));
    }

    /**
     * 删除采购原始数据
     */
    @RequiresPermissions("system:purchase:remove")
    @Log(title = "采购原始数据", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(rptPurchaseService.deleteRptPurchaseByIds(ids));
    }
}
